package com.zFace.多线程轮流打印;

/**
 * 用 while 循环实现 三个线程轮流打印十次
 */
public class Demo1 {
	private static int index = 1;

	public static void main(String[] args) {
		Thread t1 = new Thread(new Runnable() {
			public void run() {
				while (true) {
					if (index > 30) {
						break;
					}
					if (index % 3 == 1) {
						System.out.println("a");
						index++;
					}
				}
			}
		});
		Thread t2 = new Thread(new Runnable() {
			@Override
			public void run() {
				while (true) {
					if (index > 30) {
						break;
					}
					if (index % 3 == 2) {
						System.out.println("b");
						index++;
					}
				}
			}
		});
		Thread t3 = new Thread(new Runnable() {
			@Override
			public void run() {
				while (true) {
					if (index > 30) {
						break;
					}
					if (index % 3 == 0) {
						System.out.println("c");
						index++;
					}
				}
			}
		});

		t1.start();
		t2.start();
		t3.start();
	}
}
